package com.acwing.lc.part1;

/**
 * @author rkc
 * @date 2022/9/9 10:09
 */
public class LC12整数转罗马数字 {

    private final static int[] vals = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
    private final static String[] unit = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};

    public String intToRoman(int num) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 13; i++) {
            while (num >= vals[i]) {
                num -= vals[i];
                sb.append(unit[i]);
            }
        }
        return sb.toString();
    }
}
